<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
	<title>权限管理系统 - 用户管理</title>
	<meta th:remove="tag" th:include="base/include :: head" />
	<script type="text/javascript">
		$(function(){
			//左边当前菜单高亮，inculde里定义
			activeLeftNav("usermanage");
		});
	</script>
</head>
<body>
	<!-- 头部 -->
	<div th:replace="base/include :: top"></div>

    <div class="container-fluid">
      <div class="row">
        <!-- 左边菜单 -->
        <div th:replace="base/include :: left"></div>
        
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        	<ol class="breadcrumb">
			  <li><a th:href="@{/}" href="#">主页</a></li>
			  <li><a th:href="@{/user/findUsers}" href="#">用户管理</a></li>
			  <li class="active">用户列表</li>
			</ol>
			<div class="form-group">
				<a href="#" class="btn btn-primary" th:href="@{/user/userInfoInput}">新增用户</a>
				<button type="button" class="btn btn-primary">批量分配角色</button>
			</div>
          <div class="table-responsive">
            <table class="table table-striped table-bordered table-hover">
              <thead>
                <tr>
                  <th>序号</th>
                  <th>用户名</th>
                  <th>姓名</th>
                  <th>系统内置</th>
                  <th>状态</th>
                  <th class="text-center">操作</th>
                </tr>
              </thead>
              <tbody>
                <tr th:each="user,iterStat : ${page.list}">
                  <td th:text="${iterStat.count}">1</td>
                  <td th:text="${user.username}">test</td>
                  <td th:text="${user.realname}">testname</td>
                  <td th:text="${user.systemdefine}? #{yesno.yes} : #{yesno.no}">yes</td>
                  <td th:text="${user.enabled}? #{state.true} : #{state.false}">enabled</td>
                  <td>
                  	<div class="center-block" style="max-width:250px;">
	                  	<a href="#" class="btn btn-primary btn-xs" th:href="@{'/user/accessRoles/'+${user.id}}">分配角色</a>
	                  	<a href="#" class="btn btn-primary btn-xs" th:href="@{'/user/viewInfo/'+${user.id}}">查看</a>
	                  	<a th:unless="${user.systemdefine}" href="#" class="btn btn-primary btn-xs" th:href="@{'/user/userInfoInput/'+${user.id}}">修改</a>
	                  	<!-- <a href="#" class="btn btn-primary btn-xs" >禁用</a> -->
	                  	<button th:if="${!user.systemdefine and user.enabled}" type="button" class="btn btn-primary btn-xs" 
	                  			th:onclick="|disabledUser('${user.id}', '${user.realname}', true)|">禁用</button>
	                    <button th:if="${!user.systemdefine and !user.enabled}" type="button" class="btn btn-primary btn-xs" 
	                  			th:onclick="|disabledUser('${user.id}', '${user.realname}', false)|">启用</button>
                  	</div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
    <script th:inline="text" type="text/javascript">
    	function disabledUser(userid,name,flag){
    		if(!window.confirm("确定"+(flag?"禁用":"启用")+"【"+name+"】吗？"))
    			return ;
    		var href = "[[${#httpServletRequest.getContextPath()}]]/user/disableUser/"+userid;
    		if(flag) 
    			href +="?enabled=true";
    		window.location.href=href;
    	}
    </script>
   </body>
</html>